package com.twq.oo.hierarchy

/**
 * Created by tangweiqun on 2017/11/28.
 */
object BottomType {
  def main(args: Array[String]): Unit = {
    //1、scala.Null – null引用的类型，和值类型是不兼容的
    //val i: Int = null  //<console>:11: error: an expression of type Null is ineligible for implicit conversion


    //2、Nothing的用处，因为Nothing是所有类型的子类，也是Int的子类，所以下面的代码是可以成功的
    def divide(x: Int, y: Int): Int =
      if (y != 0) x / y
      else error("can't divide by zero")

    def sre(): String = {
      null //null 是所有引用类型的子类
    }
  }

  def error(message: String): Nothing = //Nothing 程序终止，返回Nothing
    throw new RuntimeException(message)
}
